from .shoutcut_import import *
from app.controller.validate.category_validate import CategoryPostValidate
from app.model.category_model import CategoryModel
bp = V1BluePoint('category', __name__, url_prefix='')


@bp.route('category', methods=['POST'])
@user_require
@validate_form(CategoryPostValidate)
def post_category():
    category = CategoryModel(request.json)
    sqla_db.session.add(category)
    sqla_db.session.commit()
    if not category.id:
        return error_json(ResponseCode.INTERNAL_SERVER_ERROR, '类型保存失败 数据库异常')
    return success_json({'id': category.id})